      *> File Name     000025_ConversionOperators.cbl.
      *> Description   Defining conversion operators.
      *> Project Type  Console application.
      *> CodePlex URL  http://cobol.codeplex.com/
      
       program-id.   Main.
       repository.
           class byte         as "System.Byte"
           class wrapped-byte as "WrappedByte"
           class sys-console  as "System.Console"
           .
       working-storage section.
       01  b   byte.
       01  wb  wrapped-byte.
       procedure division.
           move "Defining Conversion Operators" to sys-console::"Title"

           move 42 to b
           move b to wb *> implicit conversion
           display wb
           
           move 84 to b
           move b as wrapped-byte to wb *> explicit conversion
           display wb
       
           display "Press any key to continue . . . " no advancing
           invoke sys-console::"ReadKey"(true)
           .
       end program   Main.
       
       class-id.     WrappedByte.
       repository.
           class byte as "System.Byte"
           .
       factory.
      *>
       operator-id. explicit
       linkage section.
       01  b   byte.
       01  wb  WrappedByte.
       procedure division using by value b returning wb.
            move self::"New"(b) to wb
            .
       end operator.
      *>
       operator-id. implicit
       linkage section.
       01  b   byte.
       01  wb  WrappedByte.
       procedure division using by value b returning wb.
            move self::"New"(b) to wb
            .
       end operator.
      *>
       end factory.
      *>
       object.
       working-storage section.
       01  _b  byte protected.
      *>
       method-id.    New.
       procedure division using b as byte.
           move b to _b.
       end method    New.
      *>
       method-id     ToString override.
       procedure division returning s as string.
           move _b to s
       end method    ToString.
      *>
       end object.
       end class     WrappedByte.